package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.CmsHelp;
import com.ruoyi.cms.service.ICmsHelpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帮助文档Controller
 * 
 * @author zouhuu
 * @date 2022-08-04
 */
@RestController
@RequestMapping("/cms/cmsHelp")
public class CmsHelpController extends BaseController
{
    @Autowired
    private ICmsHelpService cmsHelpService;

    /**
     * 查询帮助文档列表
     */
    @PreAuthorize("@ss.hasPermi('cms:cmsHelp:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsHelp cmsHelp)
    {
        startPage();
        List<CmsHelp> list = cmsHelpService.selectCmsHelpList(cmsHelp);
        return getDataTable(list);
    }

    /**
     * 导出帮助文档列表
     */
    @PreAuthorize("@ss.hasPermi('cms:cmsHelp:export')")
    @Log(title = "帮助文档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsHelp cmsHelp)
    {
        List<CmsHelp> list = cmsHelpService.selectCmsHelpList(cmsHelp);
        ExcelUtil<CmsHelp> util = new ExcelUtil<CmsHelp>(CmsHelp.class);
        util.exportExcel(response, list, "帮助文档数据");
    }

    /**
     * 获取帮助文档详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:cmsHelp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsHelpService.selectCmsHelpById(id));
    }

    /**
     * 新增帮助文档
     */
    @PreAuthorize("@ss.hasPermi('cms:cmsHelp:add')")
    @Log(title = "帮助文档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsHelp cmsHelp)
    {
        cmsHelp.setUserId(SecurityUtils.getUserId());
        cmsHelp.setDeptId(SecurityUtils.getDeptId());
        cmsHelp.setCreateBy(SecurityUtils.getUsername());
        return toAjax(cmsHelpService.insertCmsHelp(cmsHelp));
    }

    /**
     * 修改帮助文档
     */
    @PreAuthorize("@ss.hasPermi('cms:cmsHelp:edit')")
    @Log(title = "帮助文档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsHelp cmsHelp)
    {
        cmsHelp.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(cmsHelpService.updateCmsHelp(cmsHelp));
    }

    /**
     * 删除帮助文档
     */
    @PreAuthorize("@ss.hasPermi('cms:cmsHelp:remove')")
    @Log(title = "帮助文档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsHelpService.deleteCmsHelpByIds(ids));
    }
}
